package com.czxy.config;

import inteceptor.MyIn01;
import inteceptor.MyIn02;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.*;

import javax.annotation.Resource;

//明确这个类是配置类
@Configuration
//明确要扫描的controller包
@ComponentScan({"com.czxy.controller"})
@EnableWebMvc  // 支持字符串日期自动转换成Date日期
public class SpringMVCConfig  extends WebMvcConfigurerAdapter {


    @Resource
    private MyIn01 myIn01;
    @Resource
    private MyIn02 myIn02;


    @Override
    public void addInterceptors(InterceptorRegistry registry){

        InterceptorRegistration registration = registry.addInterceptor(myIn01);
        registration.addPathPatterns("/**");


        InterceptorRegistration registration2 = registry.addInterceptor(myIn02);
        registration2.addPathPatterns("/**");

    }


//    // 添加视图解析器
//    @Bean
//    public InternalResourceViewResolver viewResolver(){
//        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
//        viewResolver.setPrefix("/user/");
//        viewResolver.setSuffix(".jsp");
//        return viewResolver;
//    }

    @Bean
    public CommonsMultipartResolver multipartResolver(){
        CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
        // 设置所有的上传文件的总大小 10M
        multipartResolver.setMaxInMemorySize(10*1024*1024);
        // 设置单个文件上传的大小 4M
        multipartResolver.setMaxUploadSize(4*1024*1024);
        multipartResolver.setDefaultEncoding("utf-8");
        return multipartResolver;
    }



}
